/**
  ******************************************************************************
  * @file    User/tk_define.h
  * @author  JUSHENG Application Team
  * @version V1.0.0
  * @date    03-18-2022
  * @brief   tk process body header file
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; COPYRIGHT 2022 JUSHENG</center></h2>
  *
  *
  */ 
  
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __TK_DEFINE_H__
#define __TK_DEFINE_H__

#ifdef __cplusplus
 extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "include.h"
#include "tk_cfg.h"
     

#define TK_PB0            (0  <<16)
#define TK_PB1            (1  <<16)
#define TK_PB2            (2  <<16)
#define TK_PB3            (3  <<16)
#define TK_PB4            (4  <<16)
#define TK_PB5            (5  <<16)
#define TK_PB6            (6  <<16)
#define TK_PB7            (7  <<16)
#define TK_PB8            (8  <<16)
#define TK_PB9            (9  <<16)
#define TK_PA0            (10 <<16)
#define TK_PA1            (11 <<16)
#define TK_PA2            (12 <<16)
#define TK_PA3            (13 <<16)
#define TK_PA4            (14 <<16)
#define TK_PA5            (15 <<16)
#define TK_PA6            (16 <<16)
#define TK_PA7            (17 <<16)
#define TK_PA8            (18 <<16)
#define TK_PA9            (19 <<16)
#define TK_PA10           (20 <<16)
#define TK_PA11           (21 <<16)
#define TK_PA12           (22 <<16)
#define TK_PA13           (23 <<16)
#define TK_PA14           (24 <<16)
#define TK_PA15           (25 <<16)
#define TK_NONE           (27 <<16)

#define TK_WKP_EN         0x800000
#define TK_ALL_FF         0xffff

#define TK_WDT_EN         0
#define CLEAR_WDT_PND     ll_wdt_feed(WDT);

#define TK_THRE(n)       (u16)((n)&0xffff)
#define TK_BIT_FLAG(n)   (u8)(((n)>>16)&0xff)
#define TK_BIT(n)        (u32)(1<<(((n)>>16)&0x1f))
#define TK_WKP_BIT(n)    (u32)((((n)>>23)&0x1)<<TK_PORT_BIT(n))

#define TK_BIT_EN  ((TK_BIT(TK_0)  | TK_BIT(TK_1)  | TK_BIT(TK_2)  | TK_BIT(TK_3)  | TK_BIT(TK_4) | \
                     TK_BIT(TK_5)  | TK_BIT(TK_6)  | TK_BIT(TK_7)  | TK_BIT(TK_8)  | TK_BIT(TK_9) | \
                     TK_BIT(TK_10) | TK_BIT(TK_11) | TK_BIT(TK_12) | TK_BIT(TK_13) | TK_BIT(TK_14) | \
                     TK_BIT(TK_15) | TK_BIT(TK_16) | TK_BIT(TK_17) | TK_BIT(TK_18) | TK_BIT(TK_19) | \
                     TK_BIT(TK_20) | TK_BIT(TK_21) | TK_BIT(TK_22) | TK_BIT(TK_23) | TK_BIT(TK_24) | \
                     TK_BIT(TK_25) ) & 0x3ffffff)

#define TK_WKP_BIT_EN ((TK_WKP_BIT(TK_0)  | TK_WKP_BIT(TK_1)  | TK_WKP_BIT(TK_2)  | TK_WKP_BIT(TK_3)  | TK_WKP_BIT(TK_4) | \
                        TK_WKP_BIT(TK_5)  | TK_WKP_BIT(TK_6)  | TK_WKP_BIT(TK_7)  | TK_WKP_BIT(TK_8)  | TK_WKP_BIT(TK_9) | \
                        TK_WKP_BIT(TK_10) | TK_WKP_BIT(TK_11) | TK_WKP_BIT(TK_12) | TK_WKP_BIT(TK_13) | TK_WKP_BIT(TK_14) | \
                        TK_WKP_BIT(TK_15) | TK_WKP_BIT(TK_16) | TK_WKP_BIT(TK_17) | TK_WKP_BIT(TK_18) | TK_WKP_BIT(TK_19) | \
                        TK_WKP_BIT(TK_20) | TK_WKP_BIT(TK_21) | TK_WKP_BIT(TK_22) | TK_WKP_BIT(TK_23) | TK_WKP_BIT(TK_24) | \
                        TK_WKP_BIT(TK_25) ) & 0x3ffffff)

#define TK_THRE_ALL  TK_THRE(TK_0)   ,  TK_THRE(TK_1)   ,  TK_THRE(TK_2)   ,  TK_THRE(TK_3)   ,  TK_THRE(TK_4)   ,\
                     TK_THRE(TK_5)   ,  TK_THRE(TK_6)   ,  TK_THRE(TK_7)   ,  TK_THRE(TK_8)   ,  TK_THRE(TK_9)   ,\
                     TK_THRE(TK_10)  ,  TK_THRE(TK_11)  ,  TK_THRE(TK_12)  ,  TK_THRE(TK_13)  ,  TK_THRE(TK_14)  ,\
                     TK_THRE(TK_15)  ,  TK_THRE(TK_16)  ,  TK_THRE(TK_17)  ,  TK_THRE(TK_18)  ,  TK_THRE(TK_19)  ,\
                     TK_THRE(TK_20)  ,  TK_THRE(TK_21)  ,  TK_THRE(TK_22)  ,  TK_THRE(TK_23)  ,  TK_THRE(TK_24)  ,\
                     TK_THRE(TK_25)  ,


typedef struct {
    u32 buf;
    u32 tk_bit_en;
    u32 reserverd0;
    u32 reserverd1;
    u32 reserverd2;
    u32 systick;
    u32 swd_buf;
} TK_StructDef;   

typedef struct {
    u8  lwfltr_value;
    u8  two_keys_proc;
    u8  multi_keys_proc;
    u8  filter_cnt;
    u8  bl_update_level;
    u8  hold_dowm_release_time;
    u8  low_power_timer_time;
} TK_ProcDef;


#define TK_UART_BIT_AF         5
#define TK_UART_BIT_PA_B       9
#define TK_UART_BIT_UART0_1    7
typedef enum {
    UART0_TX_PA11_RX_PA10  =  (LL_GPIO_PIN_11)| (LL_GPIO_AF_0 << TK_UART_BIT_AF)| (0 << TK_UART_BIT_PA_B)|  (LL_GPIO_PIN_10 << 16)| (LL_GPIO_AF_0 << (TK_UART_BIT_AF + 16))| (0 << (TK_UART_BIT_PA_B + 16)), 
    UART0_TX_PA11_RX_PA14  =  (LL_GPIO_PIN_11)| (LL_GPIO_AF_0 << TK_UART_BIT_AF)| (0 << TK_UART_BIT_PA_B)|  (LL_GPIO_PIN_14 << 16)| (LL_GPIO_AF_0 << (TK_UART_BIT_AF + 16))| (0 << (TK_UART_BIT_PA_B + 16)), 
    UART0_TX_PA11_RX_PB3   =  (LL_GPIO_PIN_11)| (LL_GPIO_AF_0 << TK_UART_BIT_AF)| (0 << TK_UART_BIT_PA_B)|  (LL_GPIO_PIN_3  << 16)| (LL_GPIO_AF_0 << (TK_UART_BIT_AF + 16))| (1 << (TK_UART_BIT_PA_B + 16)), 
    UART0_TX_PA11_RX_PB6   =  (LL_GPIO_PIN_11)| (LL_GPIO_AF_0 << TK_UART_BIT_AF)| (0 << TK_UART_BIT_PA_B)|  (LL_GPIO_PIN_6  << 16)| (LL_GPIO_AF_1 << (TK_UART_BIT_AF + 16))| (1 << (TK_UART_BIT_PA_B + 16)), 
    UART0_TX_PA11_RX_PB10  =  (LL_GPIO_PIN_11)| (LL_GPIO_AF_0 << TK_UART_BIT_AF)| (0 << TK_UART_BIT_PA_B)|  (LL_GPIO_PIN_10 << 16)| (LL_GPIO_AF_1 << (TK_UART_BIT_AF + 16))| (1 << (TK_UART_BIT_PA_B + 16)), 
                                                                                                                                                                                    
    UART0_TX_PA15_RX_PA10  =  (LL_GPIO_PIN_15)| (LL_GPIO_AF_0 << TK_UART_BIT_AF)| (0 << TK_UART_BIT_PA_B)|  (LL_GPIO_PIN_10 << 16)| (LL_GPIO_AF_0 << (TK_UART_BIT_AF + 16))| (0 << (TK_UART_BIT_PA_B + 16)),  
    UART0_TX_PA15_RX_PA14  =  (LL_GPIO_PIN_15)| (LL_GPIO_AF_0 << TK_UART_BIT_AF)| (0 << TK_UART_BIT_PA_B)|  (LL_GPIO_PIN_14 << 16)| (LL_GPIO_AF_0 << (TK_UART_BIT_AF + 16))| (0 << (TK_UART_BIT_PA_B + 16)),  
    UART0_TX_PA15_RX_PB3   =  (LL_GPIO_PIN_15)| (LL_GPIO_AF_0 << TK_UART_BIT_AF)| (0 << TK_UART_BIT_PA_B)|  (LL_GPIO_PIN_3  << 16)| (LL_GPIO_AF_0 << (TK_UART_BIT_AF + 16))| (1 << (TK_UART_BIT_PA_B + 16)),  
    UART0_TX_PA15_RX_PB6   =  (LL_GPIO_PIN_15)| (LL_GPIO_AF_0 << TK_UART_BIT_AF)| (0 << TK_UART_BIT_PA_B)|  (LL_GPIO_PIN_6  << 16)| (LL_GPIO_AF_1 << (TK_UART_BIT_AF + 16))| (1 << (TK_UART_BIT_PA_B + 16)),  
    UART0_TX_PA15_RX_PB10  =  (LL_GPIO_PIN_15)| (LL_GPIO_AF_0 << TK_UART_BIT_AF)| (0 << TK_UART_BIT_PA_B)|  (LL_GPIO_PIN_10 << 16)| (LL_GPIO_AF_1 << (TK_UART_BIT_AF + 16))| (1 << (TK_UART_BIT_PA_B + 16)),  
                                                                                                                                                                                    
    UART0_TX_PB4_RX_PA10   =  (LL_GPIO_PIN_4) | (LL_GPIO_AF_0 << TK_UART_BIT_AF)| (1 << TK_UART_BIT_PA_B)|  (LL_GPIO_PIN_10 << 16)| (LL_GPIO_AF_0 << (TK_UART_BIT_AF + 16))| (0 << (TK_UART_BIT_PA_B + 16)), 
    UART0_TX_PB4_RX_PA14   =  (LL_GPIO_PIN_4) | (LL_GPIO_AF_0 << TK_UART_BIT_AF)| (1 << TK_UART_BIT_PA_B)|  (LL_GPIO_PIN_14 << 16)| (LL_GPIO_AF_0 << (TK_UART_BIT_AF + 16))| (0 << (TK_UART_BIT_PA_B + 16)), 
    UART0_TX_PB4_RX_PB3    =  (LL_GPIO_PIN_4) | (LL_GPIO_AF_0 << TK_UART_BIT_AF)| (1 << TK_UART_BIT_PA_B)|  (LL_GPIO_PIN_3  << 16)| (LL_GPIO_AF_0 << (TK_UART_BIT_AF + 16))| (1 << (TK_UART_BIT_PA_B + 16)), 
    UART0_TX_PB4_RX_PB6    =  (LL_GPIO_PIN_4) | (LL_GPIO_AF_0 << TK_UART_BIT_AF)| (1 << TK_UART_BIT_PA_B)|  (LL_GPIO_PIN_6  << 16)| (LL_GPIO_AF_1 << (TK_UART_BIT_AF + 16))| (1 << (TK_UART_BIT_PA_B + 16)), 
    UART0_TX_PB4_RX_PB10   =  (LL_GPIO_PIN_4) | (LL_GPIO_AF_0 << TK_UART_BIT_AF)| (1 << TK_UART_BIT_PA_B)|  (LL_GPIO_PIN_10 << 16)| (LL_GPIO_AF_1 << (TK_UART_BIT_AF + 16))| (1 << (TK_UART_BIT_PA_B + 16)), 
                                                                                                                                                                                    
    UART0_TX_PB11_RX_PA10  =  (LL_GPIO_PIN_11)| (LL_GPIO_AF_1 << TK_UART_BIT_AF)| (1 << TK_UART_BIT_PA_B)|  (LL_GPIO_PIN_10 << 16)| (LL_GPIO_AF_0 << (TK_UART_BIT_AF + 16))| (0 << (TK_UART_BIT_PA_B + 16)),  
    UART0_TX_PB11_RX_PA14  =  (LL_GPIO_PIN_11)| (LL_GPIO_AF_1 << TK_UART_BIT_AF)| (1 << TK_UART_BIT_PA_B)|  (LL_GPIO_PIN_14 << 16)| (LL_GPIO_AF_0 << (TK_UART_BIT_AF + 16))| (0 << (TK_UART_BIT_PA_B + 16)),  
    UART0_TX_PB11_RX_PB3   =  (LL_GPIO_PIN_11)| (LL_GPIO_AF_1 << TK_UART_BIT_AF)| (1 << TK_UART_BIT_PA_B)|  (LL_GPIO_PIN_3  << 16)| (LL_GPIO_AF_0 << (TK_UART_BIT_AF + 16))| (1 << (TK_UART_BIT_PA_B + 16)),  
    UART0_TX_PB11_RX_PB6   =  (LL_GPIO_PIN_11)| (LL_GPIO_AF_1 << TK_UART_BIT_AF)| (1 << TK_UART_BIT_PA_B)|  (LL_GPIO_PIN_6  << 16)| (LL_GPIO_AF_1 << (TK_UART_BIT_AF + 16))| (1 << (TK_UART_BIT_PA_B + 16)),  
    UART0_TX_PB11_RX_PB10  =  (LL_GPIO_PIN_11)| (LL_GPIO_AF_1 << TK_UART_BIT_AF)| (1 << TK_UART_BIT_PA_B)|  (LL_GPIO_PIN_10 << 16)| (LL_GPIO_AF_1 << (TK_UART_BIT_AF + 16))| (1 << (TK_UART_BIT_PA_B + 16)),  
                                                                                                                                                                                    
    UART1_TX_PA1_RX_PA0    =  (LL_GPIO_PIN_1) | (LL_GPIO_AF_1 << TK_UART_BIT_AF)| (0 << TK_UART_BIT_PA_B)|  (LL_GPIO_PIN_0 << 16) | (LL_GPIO_AF_1 << (TK_UART_BIT_AF + 16))| (0 << (TK_UART_BIT_PA_B + 16))| (1<< TK_UART_BIT_UART0_1),  
    UART1_TX_PA1_RX_PA8    =  (LL_GPIO_PIN_1) | (LL_GPIO_AF_1 << TK_UART_BIT_AF)| (0 << TK_UART_BIT_PA_B)|  (LL_GPIO_PIN_8 << 16) | (LL_GPIO_AF_1 << (TK_UART_BIT_AF + 16))| (0 << (TK_UART_BIT_PA_B + 16))| (1<< TK_UART_BIT_UART0_1),  
    UART1_TX_PA1_RX_PB1    =  (LL_GPIO_PIN_1) | (LL_GPIO_AF_1 << TK_UART_BIT_AF)| (0 << TK_UART_BIT_PA_B)|  (LL_GPIO_PIN_1 << 16) | (LL_GPIO_AF_0 << (TK_UART_BIT_AF + 16))| (1 << (TK_UART_BIT_PA_B + 16))| (1<< TK_UART_BIT_UART0_1),  
                                                                                                                                                                                                             
    UART1_TX_PB2_RX_PA0    =  (LL_GPIO_PIN_2) | (LL_GPIO_AF_0 << TK_UART_BIT_AF)| (1 << TK_UART_BIT_PA_B)|  (LL_GPIO_PIN_0 << 16) | (LL_GPIO_AF_1 << (TK_UART_BIT_AF + 16))| (0 << (TK_UART_BIT_PA_B + 16))| (1<< TK_UART_BIT_UART0_1),  
    UART1_TX_PB2_RX_PA8    =  (LL_GPIO_PIN_2) | (LL_GPIO_AF_0 << TK_UART_BIT_AF)| (1 << TK_UART_BIT_PA_B)|  (LL_GPIO_PIN_8 << 16) | (LL_GPIO_AF_1 << (TK_UART_BIT_AF + 16))| (0 << (TK_UART_BIT_PA_B + 16))| (1<< TK_UART_BIT_UART0_1),  
    UART1_TX_PB2_RX_PB1    =  (LL_GPIO_PIN_2) | (LL_GPIO_AF_0 << TK_UART_BIT_AF)| (1 << TK_UART_BIT_PA_B)|  (LL_GPIO_PIN_1 << 16) | (LL_GPIO_AF_0 << (TK_UART_BIT_AF + 16))| (1 << (TK_UART_BIT_PA_B + 16))| (1<< TK_UART_BIT_UART0_1),  

}TYPE_ENUM_TK_UART_SEL;

u8 tk_struct_init(TK_StructDef *p,TK_ProcDef *tk_proc);
u8 tk_ctrl_init(void);
void tk_lp_ctrl_init(void);

/**
  * @}
  */ 

#ifdef __cplusplus
}
#endif

#endif //__TK_DEFINE_H__

/**
  * @}
  */

/**
  * @}
  */

/*************************** (C) COPYRIGHT 2022 JUSHENG ***** END OF FILE *****/

